<?php
/**
 * Created by PhpStorm.
 * User: 10267
 * Date: 2014/12/3
 * Time: 14:27
 */

class PubDict {

    public static $dict;

    public static function getDict($game, $type)
    {
        $type = ucfirst($type);

        $result = self::getNormal($game, $type);

        return $result;
    }

    private static function getNormal($game, $type){
        $dbLink = new PubDbLink('dbSelf', PubDatabase::getDictDbName($game));
        $sql = "select dict_key,dict_value from normal_dict where dict_type=:type";
        return $dbLink->getDict($sql,"dict_key","dict_value", array(':type' => $type));
    }

    public static function dict($game, $type){
        if(!isset(self::$dict[$game.'-'.$type])){
            //$dbLink = new PubDbLink('dbSelf', 'RomaMgmtDB');
            $dbLink = new PubDbLink('dbSelf', PubDatabase::getMgmtDbName('', $game));
            $sql = "select dicid,dicdesc from tblDictionary where dictype=:type";
            self::$dict[$game.'-'.$type] = $dbLink->getDict($sql,"dicid","dicdesc", array(':type' => $type));
        }

        return self::$dict[$game.'-'.$type];

    }

    public static function dictItem($itemArr){
        $dbLink = new PubDbLink('dbSelf', 'RomaMgmtDB');
        $sql = "select `id`,`name` from tblItemDictionary where `id` in (:arr)";
        $args = array('arr' => $itemArr);

        return $dbLink->getDict($sql, "id", "name", $args);
    }

} 